package org.stone.project.tx.service.impl;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.stone.project.tx.model.Message;
import org.stone.project.tx.pojo.vo.MessageClientVo;
import org.stone.project.tx.pojo.vo.MessageVo;
import org.stone.project.tx.service.MqMsgSender;
import org.stone.project.tx.service.MsgSendUserTypeHandlerAdapter;
import org.stone.project.tx.service.MsgService;
import org.stone.project.tx.sysEnum.ReceiveType;

@Service
public class MsgServiceImpl implements MsgService {
    @Autowired
    private MsgSendUserTypeHandlerAdapter msgSendUserTypeHandlerAdapter;

    @Autowired
    private MqMsgSender mqMsgSender;

    @Override
    public void sendMsg(MessageVo messageVo) {
        Message msg = BeanUtil.copyProperties(messageVo, Message.class);
        ReceiveType instance = ReceiveType.getInstance(msg.getReceiveType());
        switch (instance){
            case USER:
                msgSendUserTypeHandlerAdapter.sendMsg(msg);
                break;
            case ROLE:
                mqMsgSender.sendMsg(instance,msg);
                break;
            case GROUP:
                mqMsgSender.sendMsg(instance,msg);
                break;
            case ALL:
                mqMsgSender.sendMsg(instance,msg);
                break;
            default:
                throw new IllegalArgumentException("参数异常");
        }
    }

    @Override
    public void sendMsgSync(MessageVo messageVo) {
        Message msg = BeanUtil.copyProperties(messageVo, Message.class);
        ReceiveType instance = ReceiveType.getInstance(msg.getReceiveType());
        mqMsgSender.sendMsg(instance,msg);
    }
}
